package com.base.taskreports.task.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.base.taskreports.reports.service.TblCqpntPointInFlowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.base.taskreports.common.annotation.TBatchLog;
import com.base.taskreports.reports.entiyt.jfu.TblCqpntPointOutFlowEnyity;
import com.base.taskreports.reports.entiyt.master.TIndicatorsEntity;
import com.base.taskreports.reports.service.TIndicatorsService;
import com.base.taskreports.reports.service.TblCqpntPointOutFlowService;
import com.base.taskreports.reports.service.TblGwTransDetailService;
import com.base.taskreports.task.service.JfuService;

//import net.sf.json.JSONObject;
@Service("jfyService")
public class JfuServiceImpl implements JfuService {

	@Autowired
	private TblCqpntPointInFlowService tblCqpntPointInFlowService;

	@Autowired
	private TblCqpntPointOutFlowService tblCqpntPointOutFlowService;
	
	@Autowired
	private TIndicatorsService tIndicatorsService;
	
	
	@Autowired
	private TblGwTransDetailService TblGwTransDetailService;
	
	
	//外部积分（转接/兑换）承兑金额浮动告警
	@Override
	@TBatchLog("JFU_M001")
	public void getJFU_M001(String DateTime) {
		// TODO Auto-generated method stub
		//查询积分送 指标值   外部积分金额
		String selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory = TblGwTransDetailService.selectExternalIntegralAcceptanceAmountFloatingAlarm(DateTime);
		TIndicatorsEntity tIndicatorsEntity = new TIndicatorsEntity();
		tIndicatorsEntity.setIndicatorCode("JFU_M001");
		tIndicatorsEntity.setIndicatorValue(selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory);
		tIndicatorsService.saveTIndicators(tIndicatorsEntity);
	}
	//各积分类别消费中各支付产品类型笔数占比浮动
	@Override
	@TBatchLog("JFU_M002")
	public void getJFU_M002(String DateTime) {
		// TODO Auto-generated method stub
		//查询积分送 指标值   各积分类别消费中各支付产品类型笔数
		 List<TblCqpntPointOutFlowEnyity> selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory = tblCqpntPointOutFlowService.selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory(DateTime);
		if(selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory != null && selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory.size()>0) {
			for (TblCqpntPointOutFlowEnyity tblCqpntPointOutFlowEnyity : selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory) {
				//插入指标表
				TIndicatorsEntity tIndicatorsEntity = new TIndicatorsEntity();
				tIndicatorsEntity.setIndicatorCode("JFU_M002");
				tIndicatorsEntity.setParameter3(tblCqpntPointOutFlowEnyity.getPayProductTp());
				tIndicatorsEntity.setIndicatorValue(tblCqpntPointOutFlowEnyity.getRemark()!= null? tblCqpntPointOutFlowEnyity.getRemark().toString():"0");
				tIndicatorsService.saveTIndicators(tIndicatorsEntity);
			}
		}

	}
	//各积分类别消费中各支付产品类型金额占比浮动
	@Override
	@TBatchLog("JFU_M003")
	public void getJFU_M003(String DateTime) {
		//查询积分送 指标值   各积分类别消费中各支付产品类型金额
		List<TblCqpntPointOutFlowEnyity> selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory = tblCqpntPointOutFlowService.selectFloatingProportionProductTypeConsumptionRachCreditCategory(DateTime);
		if(selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory != null && selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory.size()>0) {
			for (TblCqpntPointOutFlowEnyity tblCqpntPointOutFlowEnyity : selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory) {
				//插入指标表
				TIndicatorsEntity tIndicatorsEntity = new TIndicatorsEntity();
				tIndicatorsEntity.setIndicatorCode("JFU_M003");
				tIndicatorsEntity.setParameter3(tblCqpntPointOutFlowEnyity.getPayProductTp());
				tIndicatorsEntity.setIndicatorValue(tblCqpntPointOutFlowEnyity.getRemark()!= null? tblCqpntPointOutFlowEnyity.getRemark().toString():"0");
				tIndicatorsService.saveTIndicators(tIndicatorsEntity);
			}
		}
		
	}
	//积分撤销/冲正/退货反向交易笔数占比浮动
	@Override
	@TBatchLog("JFU_M004")
	public void getJFU_M004(String DateTime) {
		//查询积分送 指标值   各积分类别消费中各支付产品类型笔数占比
		List<TblCqpntPointOutFlowEnyity> selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory = tblCqpntPointOutFlowService.selectFloatingProportionAmountRachTypeProductPaidConsumptionPointsNumberTransaction(DateTime);
		if(selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory != null && selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory.size()>0) {
			for (TblCqpntPointOutFlowEnyity tblCqpntPointOutFlowEnyity : selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory) {
				//插入指标表
				TIndicatorsEntity tIndicatorsEntity = new TIndicatorsEntity();
				tIndicatorsEntity.setIndicatorCode("JFU_M004");
				tIndicatorsEntity.setParameter3(tblCqpntPointOutFlowEnyity.getPayProductTp());
				tIndicatorsEntity.setIndicatorValue(tblCqpntPointOutFlowEnyity.getRemark()!= null? tblCqpntPointOutFlowEnyity.getRemark().toString():"0");
				tIndicatorsService.saveTIndicators(tIndicatorsEntity);
			}
		}
		
	}
	//积分撤销/冲正/退货反向交易金额占比浮动
	@Override
	@TBatchLog("JFU_M005")
	public void getJFU_M005(String DateTime) {
		//查询积分送 指标值   各积分类别消费中各支付产品类型笔数占比
		List<TblCqpntPointOutFlowEnyity> selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory = tblCqpntPointOutFlowService.selectFloatingProportionAmountRachTypeProductPaidConsumptionPointsNumberTransaction(DateTime);
		if(selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory != null && selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory.size()>0) {
			for (TblCqpntPointOutFlowEnyity tblCqpntPointOutFlowEnyity : selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory) {
				//插入指标表
				TIndicatorsEntity tIndicatorsEntity = new TIndicatorsEntity();
				tIndicatorsEntity.setIndicatorCode("JFU_M005");
				//tIndicatorsEntity.setParameter3(tblCqpntPointOutFlowEnyity.getPayProductTp());
				tIndicatorsEntity.setIndicatorValue(tblCqpntPointOutFlowEnyity.getRemark()!= null? tblCqpntPointOutFlowEnyity.getRemark().toString():"0");
				tIndicatorsService.saveTIndicators(tIndicatorsEntity);
			}
		}
		
	}
	//营销系统系统成功率
	@Override
	@TBatchLog("JFU_M006")
	public void getJFU_M006(String DateTime) {
		//查询积分送 指标值   各积分类别消费中各支付产品类型笔数占比
		List<TblCqpntPointOutFlowEnyity> selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory = tblCqpntPointOutFlowService.selectMarketingSystemCuccessRate(DateTime);
		if(selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory != null && selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory.size()>0) {
			for (TblCqpntPointOutFlowEnyity tblCqpntPointOutFlowEnyity : selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory) {
				//插入指标表
				TIndicatorsEntity tIndicatorsEntity = new TIndicatorsEntity();
				tIndicatorsEntity.setIndicatorCode("JFU_M006");
				tIndicatorsEntity.setParameter3(tblCqpntPointOutFlowEnyity.getPayProductTp());
				tIndicatorsEntity.setIndicatorValue(tblCqpntPointOutFlowEnyity.getRemark()!= null? tblCqpntPointOutFlowEnyity.getRemark().toString():"0");
				tIndicatorsService.saveTIndicators(tIndicatorsEntity);
			}
		}

	}
	//积分兑换价值比不为1笔数
	@Override
	@TBatchLog("JFU_M007")
	public void getJFU_M007(String DateTime) {
		//查询积分送 指标值   各积分类别消费中各支付产品类型笔数占比
		List<TblCqpntPointOutFlowEnyity> selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory = tblCqpntPointOutFlowService.selectTheConversionValueRatioOfPointsIsNotSingleNumber(DateTime);
		if(selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory != null && selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory.size()>0) {
			for (TblCqpntPointOutFlowEnyity tblCqpntPointOutFlowEnyity : selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory) {
				//插入指标表
				TIndicatorsEntity tIndicatorsEntity = new TIndicatorsEntity();
				tIndicatorsEntity.setIndicatorCode("JFU_M007");
				tIndicatorsEntity.setParameter3(tblCqpntPointOutFlowEnyity.getPayProductTp());
				tIndicatorsEntity.setIndicatorValue(tblCqpntPointOutFlowEnyity.getRemark()!= null? tblCqpntPointOutFlowEnyity.getRemark().toString():"0");
				tIndicatorsService.saveTIndicators(tIndicatorsEntity);
			}
		}
		
	}

	//已失效积分金额浮动比率
	@Override
	@TBatchLog("JFU_M008")
	public void getJFU_M008(String dateTime) {
		//查询积分送 指标值   已失效积分金额浮动比率
		String selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory = tblCqpntPointInFlowService.selectFloatingRateExpiredPoints(dateTime);
		TIndicatorsEntity tIndicatorsEntity = new TIndicatorsEntity();
		tIndicatorsEntity.setIndicatorCode("JFU_M008");
		tIndicatorsEntity.setIndicatorValue(selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory);
		tIndicatorsService.saveTIndicators(tIndicatorsEntity);
	}
	
	//积分兑换价值比不为1笔数 y //前50笔详情
	@Override
	public List<Object> getJFU_M007_Detail(String DateTime) {
		// TODO Auto-generated method stub
		List<Object> arrayList = new ArrayList<Object>();
		List<TblCqpntPointOutFlowEnyity> selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory = tblCqpntPointOutFlowService.selectTheTopFiftyTheConversionValueRatioOfPointsIsNotSingleNumber(DateTime);
        for (TblCqpntPointOutFlowEnyity tblCqpntPointOutFlowEnyity : selectFloatingProportionOfTheNumberOfPaymentProductsIConsumptionOfEachCreditCategory) {
        	//JSONObject json = JSONObject.fromObject(tblCqpntPointOutFlowEnyity);
    		//Object obj = JSONObject.toBean(json,TblCqpntPointOutFlowEnyity.class);
    		arrayList.add(tblCqpntPointOutFlowEnyity.getSeqId());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getTransSeq());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getAccessId());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getSysId());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getLogId());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getTraceId());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getRequestId());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getInvokeTransSeq());
    		
    		arrayList.add(tblCqpntPointOutFlowEnyity.getBussTp());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getTransCd());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getAcctEntityTp());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getAcctEntityId());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getResultAcctEntityTp());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getResultAcctEntityId());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getMobile());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getCardNo());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getPointTp());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getPointId());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getPointName());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getPointAt());
    		
    		arrayList.add(tblCqpntPointOutFlowEnyity.getResultDsctBal());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getMchntCd());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getTermId());
    		
    		arrayList.add(tblCqpntPointOutFlowEnyity.getInOutTransFlag());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getRegionCd());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getOrigTransCurrCd());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getOrigTransAt());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getTransCurrCd());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getTransAt());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getAppId());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getTransChnl());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getPayMethod());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getPayProductTp());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getSceneId());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getChnlMchntCd());
    		
    		arrayList.add(tblCqpntPointOutFlowEnyity.getFullCapIn());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getTransDt());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getTransTm());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getSysTraNo());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getTfrDtTm());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getAcptInsIdCd());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getFwdInsIdCd());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getRcvInsIdCd());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getCardAccptrTermId());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getCardAccptrCd());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getFlowSt());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getTotalRefundAt());
    		
    		arrayList.add(tblCqpntPointOutFlowEnyity.getOrigTransSeq());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getVoidTransSeq());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getSysErrCd());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getTransDigest());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getTransDtl());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getReservedField());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getRemark());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getRecCrtTs());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getRecUpdTs());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getTotalRefundPoint());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getPointRate());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getReturnTarget());
		
    		arrayList.add(tblCqpntPointOutFlowEnyity.getRemainTransDtl());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getDiscountCd());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getMchntTp());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getMchntNm());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getIssuerCd());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getCardTp());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getCardOgnz());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getCertId());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getIcTmn());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getOrderSrc());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getMchntLat());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getMchntLng());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getRefundInsAcctTp());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getRefundInsAcctId());
    		arrayList.add(tblCqpntPointOutFlowEnyity.getIsGray());
        }
		return arrayList;
		
		
	}

	
	
}
